var NodeUtil = require('./util/node-util')

// 启动端口
const port = 8100

// Log4js
const log4js = require('log4js')
const logger = log4js.getLogger()
logger.level = 'info'
log4js.configure('./config/log4js-config.json')

// Express
const express = require('express')
const app = express()

// 设置访问根目录
// app.use(express.static(path.join(__dirname, 'src')))
app.use(express.static(__dirname + '/src', { index: 'index.html' }))

// 请求拦截，记录日志
app.use(function (request, response, next) {
  logger.info('client_ip: %s, device_type: %s, source_uri: %s, ua: %s',
    NodeUtil.getClientIp(request), NodeUtil.getDeviceType(request), request.baseUrl.concat(request.url), NodeUtil.getUAString(request));
})

// 监听端口，启动
app.listen(port, () => {
  console.log('Service is started on %s port.', port)
})